class Dog {
    name: string;
    constructor(name: string) {
        this.name = name;
    }
    run () { }
    private pri () { }
    protected pro () { }
    readonly leg: number = 4;
    static food: string = 'bones';
}
//ts class中所有的属性都是实例属性，所有的方法都是原型方法
console.log(Dog);
let dog: Dog = new Dog("wang");
console.log(dog);
// dog.pro();
console.log(Dog.food);

class Husky extends Dog {
    constructor(name: string, public color: string) {
        super(name);
        //这个this一定要在super调用之后调用
        this.color = color;
        this.pro();
    }

}
//与es6不同，ts为class增加了修饰符，默认情况下是public
//如果一个类的constructor方法是private 那么这个类不能被继承也不能被实例化
let husky: Husky = new Husky('tom', 'red');
console.log(husky);
console.log(Husky.food);
Dog.food = 'change';
console.log(Husky.food);

//抽象类与多态
abstract class Animal {
    eat () {
        console.log('eat');
    }
    abstract sleep (): void
}

class Cat extends Animal {
    sleep (): void {
        console.log('cat sleep');
    }
    name: string;
    constructor(name: string) {
        super();
        this.name = name;
    }
}
let cat = new Cat("mi");
cat.eat();
cat.sleep();

class Bird extends Animal {
    sleep (): void {
        console.log('bird sleep');
    }

}
let bird = new Bird();
let animals: Animal[] = [cat, bird];
animals.forEach((animal) => animal.sleep());

//通过方法最后返回this实现链式调用

class WorkFlow {
    step1 () {
        console.log('step1');
        return this;
    }
    step2 () {
        console.log('step2');
        return this;
    }
}
let workflow = new WorkFlow();
workflow.step1().step1().step2();

class MyWorkFlow extends WorkFlow {
    next () {
        console.log('next');
        return this;
    }
}

let myworkflow = new MyWorkFlow();
myworkflow.step1().next().step2();